#ifndef _TARGETBL_CONFIG_H_
#define _TARGETBL_CONFIG_H_

typedef unsigned char   U8;
typedef unsigned short  U16;
typedef unsigned long   U32;

//------------------------------------------------------------------------------
// 设备相关的配置
//------------------------------------------------------------------------------

#include <C8051F580.h>

#define PCB_A1                      1
#define PCB_A2                      2

// 写入程序后锁定bootloader程序
#define BL_LOCK_FLASH

// 硬件进入BootLoader模式引脚,
// 如果不使用外部引脚, 注释掉它
#define BL_OVERRIDE_PIN             P3^3

// SYSCLK frequency in Hz
#define SYSCLK                      24000000UL

// Company-specific product ID
// 0x58 : PCB_A1
// 0x59 : PCB_A2
#if (PCB_VERSION < PCB_A2)
    #define TGT_PRODUCT_CODE            0x58
#elif (PCB_VERSION == PCB_A2)
    #define TGT_PRODUCT_CODE            0x59
#else
    #error "TGT_PRODUCT_CODE not defined"
#endif

// Total FLASH size in bytes
#define TGT_FLASH_SIZE              0x1FC00

// Specify 24-bit linear addresses here (do not use banked 16-bit addresses)
#define APP_FW_START_ADDR           0x0800

//------------------------------------------------------------------------------
// 不经常改动的配置
//------------------------------------------------------------------------------

// BL Firmware version
#define TGT_BL_FW_VERSION_LOW       0x00
#define TGT_BL_FW_VERSION_HIGH      0x01

// 通讯速率
#define BAUDRATE                    115200

// BL Type = UART
#define TGT_BL_TYPE                 0x01

// CRC Type = CRC-16-CCITT
#define TGT_CRC_TYPE                0x01

// Encryption Type = None
#define TGT_ENCRYPTION_TYPE         0x00

// Flash Page Size Code: 2^9 => 512 bytes
// Number of bytes per flash page
#define TGT_FLASH_PAGE_SIZE_CODE    9

// Note: For serial streams like UART where "packets" are not applicable, the packet size
// should be set to be equal to the BL buffer size.

// BL Comm Protocol Packet Size Code.
// Size of comm protocol's packet size (bytes; should be powers of 2)
// If TGT_BL_BUF_SIZE is 2^n, TGT_BL_BUF_SIZE_CODE is n.
#define TGT_BL_PKT_SIZE_CODE        7

// BL Buffer Size Code.
// Size of bootloader RX buffer (bytes; should be powers of 2)
// If TGT_BL_BUF_SIZE is 2^n, TGT_BL_BUF_SIZE_CODE is n.
#define TGT_BL_BUF_SIZE_CODE        7

// Target Serial Number (for multi-drop buses)
// 0=Disabled; Max: 7
#define DEV_SERIAL_NUMBYTES         0

// ** Ensure a UNIQUE Serial Number for each device on the same bus **
// - These are "don't care" if DEV_SERIAL_NUMBYTES is set to 0.
// - These need not be used if device addressing on a bus is handled
//   at the comm protocol level.
#define TGT_DEVICE_SERIAL0          0x01
#define TGT_DEVICE_SERIAL1          0x00

// 写FLASH的缓冲区起始地址
#define TGT_BUF_START_ADDR          0x8000

#endif // #ifndef _TARGETBL_CONFIG_H_
